const waitTime = (time = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

const userData = {
  id: 1,
  username: 'Serati Ma',
  mail: 'antdesign@alipay.com',
  createdAt:new Date(),
  defaultAccountID:1,
  accounts:[
    {
      id:1,
      address:"0xfC97a1A683FB0108299D5725BC9d72899C9A86B4",
    },
    {
      id:2,
      address:"0x1992A12a7765000E873C0ceEC7Cca2460AD586A7",
    },
    {
      id:3,
      address:"0x84986fa9f6Cd081677E2C9549c055EDf2a496703",
    },
  ]
}

export default {
  // 支持值为 Object 和 Array
  'GET /api/currentUser': userData,
  'POST /api/user/addAccount':async (req, res)=>{
    const { address, isDefault } = req.body;
    await waitTime(2000);
    res.send({
      status: 'ok',
    });
  },
  'POST /api/user/setDefaultAccount':async (req, res)=>{
    const { id } = req.body;
    await waitTime(2000);
    res.send({
      status: 'ok',
    });
  },
  'POST /api/login': async (req, res) => {
    const { password, userName, type } = req.body;
    await waitTime(2000);

    if (password === 'ant.design' && userName === 'admin') {
      res.send({
        status: 'ok',
        type,
        currentAuthority: 'admin',
      });
      return;
    }

    if (password === 'ant.design' && userName === 'user') {
      res.send({
        status: 'ok',
        type,
        currentAuthority: 'user',
      });
      return;
    }

    if (type === 'mobile') {
      res.send({
        status: 'ok',
        type,
        currentAuthority: 'admin',
      });
      return;
    }

    res.send({
      status: 'error',
      type,
      currentAuthority: 'guest',
    });
  },
  'POST /api/register': (req, res) => {
    res.send({
      status: 'ok',
      currentAuthority: 'user',
    });
  },
  'GET /api/500': (req, res) => {
    res.status(500).send({
      timestamp: 1513932555104,
      status: 500,
      error: 'error',
      message: 'error',
      path: '/base/category/list',
    });
  },
  'GET /api/404': (req, res) => {
    res.status(404).send({
      timestamp: 1513932643431,
      status: 404,
      error: 'Not Found',
      message: 'No message available',
      path: '/base/category/list/2121212',
    });
  },
  'GET /api/403': (req, res) => {
    res.status(403).send({
      timestamp: 1513932555104,
      status: 403,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
    });
  },
  'GET /api/401': (req, res) => {
    res.status(401).send({
      timestamp: 1513932555104,
      status: 401,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
    });
  },
};
